PINN with Data
Table of Contents
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="1"
import tensorflow as tf
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Properties
rho = 1
mu = 1
u_in = 1
D = 1
L = 2
x_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_xcor_Re2_L2.txt')
x_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_ycor_Re2_L2.txt')
y_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_xcor_Re2_L2.txt')
y_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_ycor_Re2_L2.txt')
p_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_xcor_Re2_L2.txt')
p_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_ycor_Re2_L2.txt')
x_vel_xcor = np.array(x_vel_xcor)
x_vel_ycor = np.array(x_vel_ycor)
y_vel_xcor = np.array(y_vel_xcor)
y_vel_ycor = np.array(y_vel_ycor)
p_xcor = np.array(p_xcor)
p_ycor = np.array(p_ycor)
observe_x = np.hstack([x_vel_xcor[:, 0].reshape(-1, 1), x_vel_ycor[:, 0].reshape(-1, 1)])
xvel_test = x_vel_xcor[:, 1].reshape(-1, 1)
yvel_test = y_vel_xcor[:, 1].reshape(-1, 1)
p_test = p_xcor[:, 1].reshape(-1, 1)
observe_y = np.hstack([xvel_test, yvel_test, p_test])
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.colorbar()
plt.clim((0, 1.5))
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=0.1, alpha=0.5)
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
None,
[observe_u, observe_v, observe_p],
num_domain = 0,
num_boundary = 0,
num_test = 100)
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr = 1e-3)
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
dde.optimizers.config.set_LBFGS_options()
model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
plt.figure(figsize = (20, 4))
plt.scatter(samples[:, 0],
samples[:, 1],
c = result[:, idx],
cmap = 'jet',
s = 2)
plt.colorbar()
plt.clim(color_legend[idx])
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.tight_layout()
plt.show()
# result_total = model.predict(observe_x)
# np.save('./data_plot/bigdata_total_x', observe_x[:, 0])
# np.save('./data_plot/bigdata_total_y', observe_x[:, 1])
# np.save('./data_plot/bigdata_total_u', result_total[:, 0])
# np.save('./data_plot/bigdata_total_v', result_total[:, 1])
# np.save('./data_plot/bigdata_total_p', result_total[:, 2])
# plt.figure(figsize=(20, 4))
# plt.scatter(observe_x[:, 0], observe_x[:, 1], c=result_total[:, 0], cmap='jet')
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])
result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)
result = model.predict(samples)
# np.save('./data_plot/bigdata_x', x)
# np.save('./data_plot/bigdata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/bigdata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/bigdata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/bigdata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/bigdata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/bigdata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/bigdata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/bigdata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/bigdata_yinv03_p', result_drawinv03[:, 2])
total_x = np.load('./data_plot/bigdata_total_x.npy')
total_p = np.load('./data_plot/bigdata_total_p.npy')
plt.figure(figsize=(20,4))
plt.scatter(total_x, total_p, s=9, color='k', label='CFD')
b_x = np.load('./data_plot/bigdata_x.npy')
b_y0_u = np.load('./data_plot/bigdata_y0_u.npy')
b_y0_v = np.load('./data_plot/bigdata_y0_v.npy')
b_y0_p = np.load('./data_plot/bigdata_y0_p.npy')
b_y03_u = np.load('./data_plot/bigdata_y03_u.npy')
b_y03_v = np.load('./data_plot/bigdata_y03_v.npy')
b_y03_p = np.load('./data_plot/bigdata_y03_p.npy')
b_yinv03_u = np.load('./data_plot/bigdata_yinv03_u.npy')
b_yinv03_v = np.load('./data_plot/bigdata_yinv03_v.npy')
b_yinv03_p = np.load('./data_plot/bigdata_yinv03_p.npy')
cfd_x_y0 = np.load('./data_plot/cfd_x_y0.npy')
cfd_x_y03 = np.load('./data_plot/cfd_x_y03.npy')
cfd_x_yinv03 = np.load('./data_plot/cfd_x_yinv03.npy')
cfd_y0_u = np.load('./data_plot/cfd_y0_u.npy')
cfd_y0_v = np.load('./data_plot/cfd_y0_v.npy')
cfd_y0_p = np.load('./data_plot/cfd_y0_p.npy')
cfd_y03_u = np.load('./data_plot/cfd_y03_u.npy')
cfd_y03_v = np.load('./data_plot/cfd_y03_v.npy')
cfd_y03_p = np.load('./data_plot/cfd_y03_p.npy')
cfd_yinv03_u = np.load('./data_plot/cfd_yinv03_u.npy')
cfd_yinv03_v = np.load('./data_plot/cfd_yinv03_v.npy')
cfd_yinv03_p = np.load('./data_plot/cfd_yinv03_p.npy')
plt.figure(figsize=(20,4))
plt.plot(b_x, b_y0_p, color='royalblue', label='y=0', linewidth=3)
plt.plot(b_x, b_y03_p, color='green', label='y=0.5', linewidth=3)
plt.plot(b_x, b_yinv03_p, color='orange', label='y=-0.5', linewidth=3)
plt.scatter(cfd_x_y0, cfd_y0_p, s=9, color='k', label='CFD')
plt.scatter(cfd_x_y03, cfd_y03_p, s=9, color='k')
plt.scatter(cfd_x_yinv03, cfd_yinv03_p, s=9, color='k')
plt.legend()
plt.show()
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Properties
mu = 1
rho = 1
u_in = 1
D = 1
L = 2
idx_025 = np.isclose(x_vel_xcor[:, 0], 0.25, atol=0.005)
idx_inv_025 = np.isclose(x_vel_xcor[:, 0], -0.25, atol=0.005)
idx_075 = np.isclose(x_vel_xcor[:, 0], 0.75, atol=0.003)
idx_inv_075 = np.isclose(x_vel_xcor[:, 0], -0.75, atol=0.003)
idx_05 = np.isclose(x_vel_xcor[:, 0], 0.5, atol=0.005)
idx_inv_05 = np.isclose(x_vel_xcor[:, 0], -0.5, atol=0.005)
idx_0 = np.isclose(x_vel_xcor[:, 0], 0, atol=0.005)
idx_1 = np.isclose(x_vel_xcor[:, 0], 1, atol=0.005)
idx_inv_1 = np.isclose(x_vel_xcor[:, 0], -1, atol=0.005)
xy_025 = np.hstack([x_vel_xcor[:, 0][idx_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_025].reshape(-1, 1)])
xy_inv_025 = np.hstack([x_vel_xcor[:, 0][idx_inv_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_025].reshape(-1, 1)])
xy_075 = np.hstack([x_vel_xcor[:, 0][idx_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_075].reshape(-1, 1)])
xy_inv_075 = np.hstack([x_vel_xcor[:, 0][idx_inv_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_075].reshape(-1, 1)])
observe_x = np.vstack([xy_025, xy_inv_025, xy_075, xy_inv_075])
xvel_025 = x_vel_xcor[:, 1][idx_025].reshape(-1, 1)
xvel_inv_025 = x_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
xvel_075 = x_vel_xcor[:, 1][idx_075].reshape(-1, 1)
xvel_inv_075 = x_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)
yvel_025 = y_vel_xcor[:, 1][idx_025].reshape(-1, 1)
yvel_inv_025 = y_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
yvel_075 = y_vel_xcor[:, 1][idx_075].reshape(-1, 1)
yvel_inv_075 = y_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)
p_025 = p_xcor[:, 1][idx_025].reshape(-1, 1)
p_inv_025 = p_xcor[:, 1][idx_inv_025].reshape(-1, 1)
p_075 = p_xcor[:, 1][idx_075].reshape(-1, 1)
p_inv_075 = p_xcor[:, 1][idx_inv_075].reshape(-1, 1)
xvel_test = np.vstack([xvel_025, xvel_inv_025, xvel_075, xvel_inv_075])
yvel_test = np.vstack([yvel_025, yvel_inv_025, yvel_075, yvel_inv_075])
p_test = np.vstack([p_025, p_inv_025, p_075, p_inv_075])
observe_y = np.hstack([xvel_test, yvel_test, p_test])
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.colorbar()
plt.clim((0, 1.5))
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
None,
[observe_u, observe_v, observe_p],
num_domain = 0,
num_boundary = 0,
num_test = 100)
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr = 1e-3)
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
dde.optimizers.config.set_LBFGS_options()
model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
plt.figure(figsize = (20, 4))
plt.scatter(samples[:, 0],
samples[:, 1],
c = result[:, idx],
cmap = 'jet',
s = 2)
plt.colorbar()
plt.clim(color_legend[idx])
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.tight_layout()
plt.show()
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])
result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)
# np.save('./data_plot/smalldata_x', x)
# np.save('./data_plot/smalldata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/smalldata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/smalldata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/smalldata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/smalldata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/smalldata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/smalldata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/smalldata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/smalldata_yinv03_p', result_drawinv03[:, 2])
# plt.figure(figsize=(20, 4))
# plt.scatter(observe_x[:, 0], observe_x[:, 1], c=result_total[:, 0], cmap='jet')
# plt.clim(0,1.5)
plt.figure(figsize=(20,4))
plt.plot(x, a, color='royalblue', label='y=0', linewidth=3)
plt.plot(x, result_draw03[:, 1], color='green', label='y=0.5', linewidth=3)
plt.plot(x, result_drawinv03[:, 1], color='orange', label='y=-0.5', linewidth=3)
plt.scatter(observe_x[:, 0][idx0], observe_y[:, 1][idx0], s=9, color='k', label='CFD')
plt.scatter(observe_x[:, 0][idx03], observe_y[:, 1][idx03], s=9, color='k')
plt.scatter(observe_x[:, 0][idxinv03], observe_y[:, 1][idxinv03], s=9, color='k')
plt.legend()
plt.show()
np.save('./data_plot/smaldata_total_p', result.reshape(-1, 1))
x = np.load('./data_plot/smaldata_total_x.npy')
y= np.load('./data_plot/smaldata_total_y.npy')
p= np.load('./data_plot/smaldata_total_p.npy')
plt.scatter(x, y, c=p, cmap='jet')
# plt.clim(0, 35)
# Properties
rho = 1
mu = 1
u_in = 1
D = 1
L = 2
idx_025 = np.isclose(x_vel_xcor[:, 0], 0.25, atol=0.005)
idx_inv_025 = np.isclose(x_vel_xcor[:, 0], -0.25, atol=0.005)
idx_075 = np.isclose(x_vel_xcor[:, 0], 0.75, atol=0.003)
idx_inv_075 = np.isclose(x_vel_xcor[:, 0], -0.75, atol=0.003)
idx_05 = np.isclose(x_vel_xcor[:, 0], 0.5, atol=0.005)
idx_inv_05 = np.isclose(x_vel_xcor[:, 0], -0.5, atol=0.005)
idx_0 = np.isclose(x_vel_xcor[:, 0], 0, atol=0.005)
idx_1 = np.isclose(x_vel_xcor[:, 0], 1, atol=0.005)
idx_inv_1 = np.isclose(x_vel_xcor[:, 0], -1, atol=0.005)
xy_025 = np.hstack([x_vel_xcor[:, 0][idx_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_025].reshape(-1, 1)])
xy_inv_025 = np.hstack([x_vel_xcor[:, 0][idx_inv_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_025].reshape(-1, 1)])
xy_075 = np.hstack([x_vel_xcor[:, 0][idx_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_075].reshape(-1, 1)])
xy_inv_075 = np.hstack([x_vel_xcor[:, 0][idx_inv_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_075].reshape(-1, 1)])
observe_x = np.vstack([xy_025, xy_inv_025, xy_075, xy_inv_075])
xvel_025 = x_vel_xcor[:, 1][idx_025].reshape(-1, 1)
xvel_inv_025 = x_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
xvel_075 = x_vel_xcor[:, 1][idx_075].reshape(-1, 1)
xvel_inv_075 = x_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)
yvel_025 = y_vel_xcor[:, 1][idx_025].reshape(-1, 1)
yvel_inv_025 = y_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
yvel_075 = y_vel_xcor[:, 1][idx_075].reshape(-1, 1)
yvel_inv_075 = y_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)
p_025 = p_xcor[:, 1][idx_025].reshape(-1, 1)
p_inv_025 = p_xcor[:, 1][idx_inv_025].reshape(-1, 1)
p_075 = p_xcor[:, 1][idx_075].reshape(-1, 1)
p_inv_075 = p_xcor[:, 1][idx_inv_075].reshape(-1, 1)
xvel_test = np.vstack([xvel_025, xvel_inv_025, xvel_075, xvel_inv_075])
yvel_test = np.vstack([yvel_025, yvel_inv_025, yvel_075, yvel_inv_075])
p_test = np.vstack([p_025, p_inv_025, p_075, p_inv_075])
observe_y = np.hstack([xvel_test, yvel_test, p_test])
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.colorbar()
plt.clim((0, 1.5))
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)
def boundary_wall(X, on_boundary):
on_wall = np.logical_and(np.logical_or(np.isclose(X[1], -D/2), np.isclose(X[1], D/2)), on_boundary)
return on_wall
def boundary_inlet(X, on_boundary):
return on_boundary and np.isclose(X[0], -L/2)
def boundary_outlet(X, on_boundary):### 6.3.2. Define PDE with Boundary & Initial Conditions
return on_boundary and np.isclose(X[0], L/2)
def pde(X, Y):
du_x = dde.grad.jacobian(Y, X, i = 0, j = 0)
du_y = dde.grad.jacobian(Y, X, i = 0, j = 1)
dv_x = dde.grad.jacobian(Y, X, i = 1, j = 0)
dv_y = dde.grad.jacobian(Y, X, i = 1, j = 1)
dp_x = dde.grad.jacobian(Y, X, i = 2, j = 0)
dp_y = dde.grad.jacobian(Y, X, i = 2, j = 1)
du_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 0)
du_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 0)
dv_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 1)
dv_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 1)
pde_u = Y[:,0:1]*du_x + Y[:,1:2]*du_y + 1/rho * dp_x - (mu/rho)*(du_xx + du_yy)
pde_v = Y[:,0:1]*dv_x + Y[:,1:2]*dv_y + 1/rho * dp_y - (mu/rho)*(dv_xx + dv_yy)
pde_cont = du_x + dv_y
return [pde_u, pde_v, pde_cont]
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
bc_wall_u = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 0)
bc_wall_v = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 1)
bc_inlet_u = dde.DirichletBC(geom, lambda X: u_in, boundary_inlet, component = 0)
bc_inlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_inlet, component = 1)
bc_outlet_p = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 2)
bc_outlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 1)
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
pde,
[bc_wall_u, bc_wall_v, bc_inlet_u, bc_inlet_v, bc_outlet_p, bc_outlet_v, observe_u, observe_v, observe_p],
num_domain = 1000,
num_boundary = 500,
num_test = 1000,
train_distribution = 'LHS')
plt.figure(figsize = (20,4))
plt.scatter(data.train_x_all[:,0], data.train_x_all[:,1], s = 0.5)
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.colorbar()
plt.clim((0, 1.5))
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr = 1e-3, loss_weights=[1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9])
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)### 7.2.5. Train (Adam Optimizer)
dde.optimizers.config.set_LBFGS_options()
model.compile("L-BFGS", loss_weights=[1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9])
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)### 7.2.7. Train More (L-BFGS Optimizer)
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
plt.figure(figsize = (20, 4))
plt.scatter(samples[:, 0],
samples[:, 1],
c = result[:, idx],
cmap = 'jet',
s = 2)
plt.colorbar()
plt.clim(color_legend[idx])
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.tight_layout()
plt.show()### 7.2.8. Plot Results (Adam + L-BFGS)
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])
result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)
# np.save('./data_plot/pdesmalldata_x', x)
# np.save('./data_plot/pdesmalldata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/pdesmalldata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/pdesmalldata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/pdesmalldata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/pdesmalldata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/pdesmalldata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/pdesmalldata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/pdesmalldata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/pdesmalldata_yinv03_p', result_drawinv03[:, 2])
# result_total = model.predict(observe_x)
# np.save('./data_plot/pdesmalldata_total_x', observe_x[:, 0])
# np.save('./data_plot/pdesmalldata_total_y', observe_x[:, 1])
# np.save('./data_plot/pdesmalldata_total_u', result_total[:, 0])
# np.save('./data_plot/pdesmalldata_total_v', result_total[:, 1])
# np.save('./data_plot/pdesmalldata_total_p', result_total[:, 2])
import pandas as pd
x_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_xcor_Re2_L2.txt')
x_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_ycor_Re2_L2.txt')
y_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_xcor_Re2_L2.txt')
y_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_ycor_Re2_L2.txt')
p_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_xcor_Re2_L2.txt')
p_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_ycor_Re2_L2.txt')
x_vel_xcor = np.array(x_vel_xcor)
x_vel_ycor = np.array(x_vel_ycor)
y_vel_xcor = np.array(y_vel_xcor)
y_vel_ycor = np.array(y_vel_ycor)
p_xcor = np.array(p_xcor)
p_ycor = np.array(p_ycor)
observe_x = np.hstack([x_vel_xcor[:, 0].reshape(-1, 1), x_vel_ycor[:, 0].reshape(-1, 1)])
xvel_test = x_vel_xcor[:, 1].reshape(-1, 1)
yvel_test = y_vel_xcor[:, 1].reshape(-1, 1)
p_test = p_xcor[:, 1].reshape(-1, 1)
observe_y = np.hstack([xvel_test, yvel_test, p_test])
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
plt.figure(figsize = (20, 4))
plt.scatter(observe_x[:, 0],
observe_x[:, 1],
c = observe_y[:, idx],
cmap = 'jet',
s = 6.5)
plt.colorbar()
plt.clim(color_legend[idx])
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.tight_layout()
plt.show()
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')